<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
  <head>
    <title>申请人---申购单</title>
    <script type="text/javascript">
      function primarySelectVendor(purchaseId,offerId,searchType){
        Ext.MessageBox.confirm('<font color=red>警告</font>','初选只能选择一次，您确定选择吗？',function (button){
          if(button=='yes'){
            Ext.Ajax.request({
              url : '/purchase/primarySelectPurchase?purchase_id='+purchaseId + "&offer_id=" + offerId,
              success : function (response, req) {
                if (Ext.util.JSON.decode(response.responseText).info === "success") {
                  purchaseForApplicantWin.destroy();
                  purchaseDS.reload();
                } else {
                  Ext.MessageBox.alert('提示', '网络通讯问题.');
                }
              },
              failure : function (result, request){
              },
              method : 'POST'
            });
          }
        });
      }

      var userViewWin;
      var id;
      var vendorId;
      var vendorName;
      Ext.onReady(function(){
        var purchaseId = new Ext.form.Hidden({
          name: 'id',
          value:'<%=params[:id]%>'
        });

        var searchType = new Ext.form.Hidden({
          name: 'search_type',
          value: '<%=params[:search_type]%>'
        });
        
        var orderNumber = new Ext.form.TextField({
          fieldLabel: '申购序号',
          allowBlank: false,
          blankText: "申购单位不能为空",
          name: 'order_number',
          readOnly: true,
          anchor: '90%'
        });
        
        var purchaseUnit = new Ext.form.TextField({
          fieldLabel: '申购单位',
          allowBlank: false,
          blankText: "申购单位不能为空",
          name: 'purchase_unit',
          anchor: '90%',
          readOnly: true
        });
        
        //申购时间
        var actionDate = new Ext.form.DateField({
          fieldLabel: '申购时间',
          name: 'action_date',
          format: 'Y-m-d', //格式化日期
          //disabledDays: [0,6],	//不让选择周六，周日
          //disabledDaysText: "周末要休息",
          invalidText: "您输入的日期格式不对，正确格式为2010-01-18",
          allowBlank: true,
          blankText: "申请日期必须选择",
          emptyText: '请选择日期...',
          anchor: '90%'
        });


        var subDept = new Ext.form.TextField({
          fieldLabel: '实验室(科室)',
          name: 'sub_dept',
          readOnly: true,
          allowBlank: false,
          anchor: '90%'
        });

        var manager = new Ext.form.TextField({
          fieldLabel: '管理人',
          name: 'manager',
          anchor: '90%',
          readOnly: true,
          value:'<%=session[:applicant_name]%>'
        });

        var fundingSource = new Ext.form.TextField({
          fieldLabel: '经费来源',
          name: 'funding_source',
          allowBlank: false,
          readOnly: true,
          anchor: '90%'
        });

        var fundingAccount = new Ext.form.TextField({
          fieldLabel: '经费账号',
          name: 'funding_account',
          readOnly: true,
          anchor: '90%'
        });

        var fundingNature = new Ext.form.TextField({
          fieldLabel: '经费性质',
          name: 'funding_nature',
          disabled: true,
          readOnly: true,
          anchor: '90%'
        });

        var productName = new Ext.form.TextField({
          fieldLabel: '产品名称',
          name: 'product_name',
          allowBlank: false,
          readOnly: true,
          anchor: '90%'
        });

        var serviceLift = new Ext.form.NumberField({
          fieldLabel: '需用时间',
          name: 'service_lift',
          allowBlank: false,
          allowDecimals: false,
          allowNegative: false,
          readOnly: true,
          disabled: true,
          anchor: '90%'
        });


        var quantity = new Ext.form.NumberField({
          fieldLabel: '台件数',
          name: 'quantity',
          allowBlank: false,
          allowDecimals: false,
          allowNegative: false,
          readOnly: true,
          anchor: '90%'
        });

        var brand = new Ext.form.TextField({
          fieldLabel: '品牌',
          name: 'brand',
          readOnly: true,
          anchor: '90%'
        });

        var model = new Ext.form.TextField({
          fieldLabel: '型号',
          allowBlank: false,
          name: 'model',
          readOnly: true,
          anchor: '90%'
        });

        var specification = new Ext.form.TextField({
          fieldLabel: '规格',
          name: 'specification',
          readOnly: true,
          anchor: '90%'
        });

        var manufacturer = new Ext.form.TextField({
          fieldLabel: '生产单位',
          name: 'manufacturer',
          readOnly: true,
          anchor: '90%'
        });

        var estimatedPrice = new Ext.form.NumberField({
          fieldLabel: '预估单价',
          name: 'estimated_price',
          allowBlank: false,
          allowNegative: false,
          readOnly: true,
          anchor: '90%'
        });
        
        var estimatedAmount = new Ext.form.NumberField({
          fieldLabel: '预估总额',
          name: 'estimated_amount',
          readOnly: true,
          allowBlank: false,
          allowNegative: false,
          anchor: '90%'
        });
        
        var qualification = new Ext.form.TextArea({
          fieldLabel: '技术指标',
          name: 'qualification',
          height:20,
          readOnly: true,
          anchor: '97%'
        });

        var serviceRequest = new Ext.form.TextArea({
          fieldLabel: '服务要求',
          name: 'service_request',
          height:20,
          readOnly: true,
          anchor: '97%'
        });

        //供货时间
        var supplyDate = new Ext.form.DateField({
          fieldLabel: '供货时间',
          name: 'supply_date',
          format: 'Y-m-d', //格式化日期
          //disabledDays: [0,6],	//不让选择周六，周日
          //disabledDaysText: "周末要休息",
          invalidText: "您输入的日期格式不对，正确格式为2010-01-18",
          allowBlank: false,
          readOnly: true,
          blankText: "申请日期必须选择",
          emptyText: '请选择日期...',
          anchor: '95%'
        });

        var supplyAddress = new Ext.form.TextField({
          fieldLabel: '供货地点',
          name: 'supply_address',
          readOnly: true,
          anchor: '96%'
        });
        
        var reason = new Ext.form.TextArea({
          fieldLabel: '理由及用途',
          allowBlank: false,
          name: 'reason',
          height:20,
          readOnly: true,
          anchor: '97%'
        });

        //竞标日期
        var beginDate = new Ext.form.DateField({
          fieldLabel: '竞标日期从',
          name: 'begin_date',
          id: 'begin_date',
          format: 'Y-m-d', //格式化日期
          width: '100',
          //disabledDays: [0,6],	//不让选择周六，周日
          //disabledDaysText: "周末要休息",
          invalidText: "您输入的日期格式不对，正确格式为2008-01-01",
          allowBlank: true,
          inputType: '2010-01-01',
          anchor: '95%',
          vtype: 'daterange',
          endDateField: 'end_date',
          allowBlank: false,
          readOnly: true
        });
        var endDate = new Ext.form.DateField({
          fieldLabel: '到',
          name: 'end_date',
          id: 'end_date',
          format: 'Y-m-d', //格式化日期
          width: '100',
          //disabledDays: [0,6],	//不让选择周六，周日
          //disabledDaysText: "周末要休息",
          invalidText: "您输入的日期格式不对，正确格式为2008-01-01",
          allowBlank: false,
          inputType: '2010-01-01',
          anchor: '95%',
          vtype: 'daterange',
          startDateField: 'begin_date',
          allowBlank: false,
          readOnly: true
        });
        
        //供应商竞价信息
        var offerDS = new Ext.data.Store({
          proxy: new Ext.data.HttpProxy({
            url: '/offer/getOffersByPurchaseId?id=' + purchaseId.getValue()
          }),
          reader: new Ext.data.JsonReader({
            totalProperty: 'totalProperty',
            root: 'root'
          }, [{
              name: 'id'
            },{
              name: 'manager'
            }, {
              name: 'product_name'
            }, {
              name: 'brand'
            }, {
              name: 'model'
            }, {
              name: 'specification'
            }, {
              name: 'manufacturer'
            }, {
              name: 'is_primary'
            }, {
              name: 'unit_price'
            }, {
              name: 'amount'
            }, {
              name: 'bid_status'
            },{
              name:'vendor_name',
              mapping:'vendor.company_name'
            },{
              name:'service_rating',
              mapping:'vendor.service_rating'
            },{
              name:'quality_rating',
              mapping:'vendor.quality_rating'
            },{
              name:'supply_count',
              mapping:'vendor.supply_count'
            },{
              name:'vendor_id',
              mapping:'vendor.id'
            }])
        });
        var offerSM = new Ext.grid.CheckboxSelectionModel();
        var offerCM = new Ext.grid.ColumnModel([new Ext.grid.RowNumberer(),offerSM, {
            header: '总额',
            dataIndex: 'amount',
            width:50,
            renderer:showAmount
          },{
            header: '供应商',
            dataIndex: 'vendor_name',
            width:130
          },{
            header: '品牌',
            dataIndex: 'brand',
            width:50
          }, {
            header: '型号规格',
            dataIndex: 'specification',
            width:80
          }, {
            header: '生产商',
            dataIndex: 'manufacturer',
            width:50
          }, {
            header: '服务评价',
            dataIndex: 'service_rating',
            renderer:showServiceRating,
            width:50
          },{
            header: '质量评价',
            dataIndex: 'quality_rating',
            renderer:showQualityRating,
            width:50
          },{
            header: '供货次数',
            dataIndex: 'supply_count',
            width:50
          },{
            header: '已初选',
            dataIndex: 'bid_status',
            width:50
          }, {
            header: '操作',
            dataIndex: 'manufacturer',
            renderer: offerActionRender,
            width:50
          }]);

        function showAmount(value){
          return '<font color=red>'+value+'</font>'
        }
        
        function showServiceRating(value){
          if(value==5){
            return '* * * * *'
          }else if(value==4){
            return '* * * *'
          }else if(value==3){
            return '* * *'
          }else if(value==2){
            return '* *'
          }else{
            return '*'
          }
        }

        function showQualityRating(value){
          if(value==5){
            return '* * * * *'
          }else if(value==4){
            return '* * * *'
          }else if(value==3){
            return '* * *'
          }else if(value==2){
            return '* *'
          }else{
            return '*'
          }
        }
        function offerActionRender(value, cellmeta, record, rowIndex, columnIndex, store){
          if(searchType.getValue() === "primary"){
            return "<a style=cursor:pointer;color:blue onclick=primarySelectVendor(" + purchaseId.getValue() + "," + store.getAt(rowIndex).get('id')+",'"+searchType.getValue()+"')>初选</a>";
          }
        }

        var offerGrid =  new Ext.grid.GridPanel({
          frame: true,
          title: '<font color=green>供应商报价</font>',
          ds: offerDS,
          cm: offerCM,
          sm: new Ext.grid.RowSelectionModel({singleSelect:true}),
          width: 720,
          height: 120,
          iconCls: 'icon-grid',loadMask: true,
          loadMask: true
        });


        offerGrid.on('rowcontextmenu', function(grid,rowindex,e){
            vendorId = offerDS.getAt(rowindex).get('vendor_id')

            id = offerDS.getAt(rowindex).get('id')
            vendorName = offerDS.getAt(rowindex).get('vendor_name')
            e.preventDefault();
            rightClick.showAt(e.getXY());
        });

        var rMenu1 = new Ext.menu.Item({
          text:'报价详情',
          handler:showOffer,
          iconCls:'viewItem'
        })

        var rMenu2 = new Ext.menu.Item({
          text:'供应商信息',
          handler:showVendor,
          iconCls:'viewItem'
        })
        var rightClick = new Ext.menu.Menu({
            id:'rightClickCont',
            items: [
                rMenu1,rMenu2
            ]
        });

        function showOffer(){
            purchaseForUserWin = new Ext.Window({
                layout: 'fit',
                width: 825,
                height: 300,
                closeAction: 'destroy',
                plain: true,
                modal: true,
                constrain:true,
                //modal: true,
                title: vendorName+'报价信息',
                autoLoad: {
                  url: "/purchase/purchaseForUser?id="+id,
                  scripts: true
                }
              });
              purchaseForUserWin.resizable = false;
              purchaseForUserWin.show();
        }

        function showVendor(){

                userViewWin = new Ext.Window({
                    title: '查看用户信息',
                    layout:'fit',
                    width:629,
                    height:400,
                    closeAction:'destroy',
                    constrain:true,
                    plain: true,
                    modal: true,
                    autoScroll:true,
                    autoLoad: {
                      url: "/purchase/userView?id=" + vendorId,
                      scripts: true
                    }
                  });
                  //userViewWin.on("destroy",function(){
                   // userDS.reload();
                  //});
                  userViewWin.resizable = false;
                  userViewWin.show();
        }
  

        //下面是对供应商的评价
        // 处理方式
        var ratingStore = new Ext.data.ArrayStore({
          //fields: ['value', 'text'],
          fields: ['text','value'],
          data : ratingDataArray
        });

        var serviceRating = new Ext.form.ComboBox({
          fieldLabel: '服务评价',
          store: ratingStore,
          valueField:'value',
          displayField:'text',
          typeAhead: true,
          mode: 'local',
          triggerAction: 'all',
          selectOnFocus:true,
          name:'service_rating',
          anchor: '95%',
          value:3
        });

        var qualityRating = new Ext.form.ComboBox({
          fieldLabel: '质量评价',
          store: ratingStore,
          valueField:'value',
          displayField:'text',
          typeAhead: true,
          mode: 'local',
          triggerAction: 'all',
          selectOnFocus:true,
          name:'quality_rating',
          anchor: '95%',
          value:3
        });
        
        var acceptanceOpinion = new Ext.form.TextArea({
          fieldLabel: '验收意见',
          name: 'acceptance_opinion',
          height:20,
          anchor: '95%'
        });

        var acceptanceFieldSet = new Ext.form.FieldSet({
          title: '<font color=red>验收信息</font>',
          autoHeight: true,
          defaults: {width: 750},
          items: [{
              layout: 'column',
              border: false,
              items: [{
                  columnWidth: .25,
                  layout: 'form',
                  border: false,
                  items: [serviceRating]
                }, {
                  columnWidth: .25,
                  layout: 'form',
                  border: false,
                  items: [qualityRating]
                }]
            },{
              layout: 'column',
              border: false,
              items: [{
                  columnWidth: 1,
                  layout: 'form',
                  border: false,
                  items: [acceptanceOpinion]
                }]
            }]
        });

        var dateFieldSet = new Ext.form.FieldSet({             
          autoHeight: true,
          defaults: {width: 750},
          title: '竞价信息',
          border: true,
          items: [{
              layout: 'column',
              border: false,
              items: [{
                  columnWidth: .25,
                  layout: 'form',
                  border: false,
                  items: [beginDate]
                }, {
                  columnWidth: .25,
                  layout: 'form',
                  border: false,
                  items: [endDate]
                }]
            }]
        });

        
        //入库日期
        //供货时间
        var entryDate = new Ext.form.DateField({
          fieldLabel: '入库日期',
          name: 'entry_date',
          format: 'Y-m-d', //格式化日期
          //disabledDays: [0,6],	//不让选择周六，周日
          //disabledDaysText: "周末要休息",
          invalidText: "您输入的日期格式不对，正确格式为2010-01-18",
          allowBlank: false,
          blankText: "申请日期必须选择",
          emptyText: '请选择日期...',
          anchor: '90%'
        });

        var entryOrderNumber = new Ext.form.TextField({
          fieldLabel: '入库单号',
          name: 'entry_order_number',
          anchor: '90%'
        });

        var invoiceNumber = new Ext.form.TextField({
          fieldLabel: '发票号',
          name: 'invoice_number',
          anchor: '90%'
        });

        var isImport = new Ext.form.RadioGroup({
          //width : 220,
          name: 'is_import',
          fieldLabel: '是否进口',
          //hideLabel:true,
          //style:'margin-left:100px;margin-top:20px',
          columns : 2,
          anchor: '90%',
          vertical :false,
          items:[
            {boxLabel:'是',inputValue:'是',name:'is_import',checked:true},
            {boxLabel:'否',inputValue:'否',name:'is_import'}
          ]
        });
        
        var produceDate = new Ext.form.DateField({
          fieldLabel: '生产日期',
          name: 'produce_date',
          format: 'Y-m-d', //格式化日期
          //disabledDays: [0,6],	//不让选择周六，周日
          //disabledDaysText: "周末要休息",
          invalidText: "您输入的日期格式不对，正确格式为2010-01-18",
          allowBlank: false,
          blankText: "申请日期必须选择",
          emptyText: '请选择日期...',
          anchor: '90%'
        });

        var purchaseDate = new Ext.form.DateField({
          fieldLabel: '购置日期',
          name: 'purchase_date',
          format: 'Y-m-d', //格式化日期
          //disabledDays: [0,6],	//不让选择周六，周日
          //disabledDaysText: "周末要休息",
          invalidText: "您输入的日期格式不对，正确格式为2010-01-18",
          allowBlank: false,
          blankText: "申请日期必须选择",
          emptyText: '请选择日期...',
          anchor: '90%'
        });

        var productSn = new Ext.form.TextField({
          fieldLabel: '出厂编号',
          name: 'product_sn',
          anchor: '90%'
        });

        var itemNo = new Ext.form.TextField({
          fieldLabel: '设备编号',
          name: 'item_no',
          anchor: '90%'
        });
        var assignmentUnit = new Ext.form.TextField({
          fieldLabel: '分配单位',
          name: 'assignment_unit',
          anchor: '90%'
        });

        var instruction = new Ext.form.TextArea({
          fieldLabel: '说明书',
          name: 'instruction',
          height:40,
          anchor: '95%'
        });

        var remark = new Ext.form.TextArea({
          fieldLabel: '备注',
          name: 'remark',
          height:20,
          anchor: '95%'
        });

        
        var entryFieldSet = new Ext.form.FieldSet({
          title: '<font color=red>入库信息</font>',
          autoHeight: true,
          defaults: {width: 750},
          items: [{
              layout: 'column',
              border: false,
              items: [{
                  columnWidth: .25,
                  layout: 'form',
                  border: false,
                  items: [entryDate]
                }, {
                  columnWidth: .25,
                  layout: 'form',
                  border: false,
                  items: [entryOrderNumber]
                },{
                  columnWidth: .25,
                  layout: 'form',
                  border: false,
                  items: [invoiceNumber]
                }, {
                  columnWidth: .25,
                  layout: 'form',
                  border: false,
                  items: [isImport]
                }]
            },{
              layout: 'column',
              border: false,
              items: [{
                  columnWidth: .25,
                  layout: 'form',
                  border: false,
                  items: [produceDate]
                }, {
                  columnWidth: .25,
                  layout: 'form',
                  border: false,
                  items: [purchaseDate]
                },{
                  columnWidth: .25,
                  layout: 'form',
                  border: false,
                  items: [productSn]
                }, {
                  columnWidth: .25,
                  layout: 'form',
                  border: false,
                  items: [itemNo]
                }]
            },{
              layout: 'column',
              border: false,
              items: [{
                  columnWidth: .25,
                  layout: 'form',
                  border: false,
                  items: [assignmentUnit]
                }]
            },{
              layout: 'column',
              border: false,
              items: [{
                  columnWidth: 1,
                  layout: 'form',
                  border: false,
                  items: [instruction]
                }]
            },{
              layout: 'column',
              border: false,
              items: [{
                  columnWidth: 1,
                  layout: 'form',
                  border: false,
                  items: [remark]
                }]
            }]
        });

        var forAccountInfo = new Ext.form.TextArea({
          fieldLabel: '报账信息',
          name: 'for_account_info',
          height:20,
          anchor: '95%'
        });
        
        //报账信息
        var accountFieldSet = new Ext.form.FieldSet({
          title: '<font color=red>报账信息</font>',
          autoHeight: true,
          defaults: {width: 750},
          items: [{
              layout: 'column',
              border: false,
              items: [{
                  columnWidth: 1,
                  layout: 'form',
                  border: false,
                  items: [forAccountInfo]
                }]
            }]
        });

        //打印申购单
        var printPurchaseButton = new Ext.Button({
          text:'下载申购单',
          handler:function(){
            var id = <%=params[:id]%>
            var path='/purchase/printPurchase?id='+id
            window.open(path,'_blank','width=1,height=1,toolbar=no,menubar=no,location=no');
          }
        })

        var printEntryButton = new Ext.Button({
          text:'下载入库单',
          handler:function(){
            var id = <%=params[:id]%>
            var path='/purchase/printEntry?id='+id
            window.open(path,'_blank','width=1,height=1,toolbar=no,menubar=no,location=no');
          }
        })
        
        //验收通过
        var acceptancePassButton = new Ext.Button({
          text: '验收通过',
          handler: function(){
            Ext.MessageBox.confirm('<font color=red>提示</font>','确定通过此次验收吗？',function (button){
              if(button=='yes'){
                Ext.Ajax.request({
                  url : '/purchase/passAcceptance?id='+purchaseId.getValue(),
                  params: {
                    service_rating: serviceRating.getValue(),
                    quality_rating: qualityRating.getValue(),
                    acceptance_opinion:acceptanceOpinion.getValue()
                  },
                  success : function (response, req) {
                    if (Ext.util.JSON.decode(response.responseText).info === "success") {
                      purchaseForApplicantWin.destroy();
                      purchaseDS.reload();
                    } else {
                      Ext.MessageBox.alert('提示', '网络通讯问题.');
                    }
                  },
                  failure : function (result, request){
                  },
                  method : 'POST'
                });
              }
            });
          }
        })

        //验收不通过
        var acceptanceRejectButton = new Ext.Button({
          text: '验收不通过',
          handler: function(){
            Ext.MessageBox.confirm('<font color=red>提示</font>','确定不通过此次验收吗？',function (button){
              if(button=='yes'){
                Ext.Ajax.request({
                  url : '/purchase/rejectAcceptance?id='+purchaseId.getValue(),
                  params: {
                    service_rating: serviceRating.getValue(),
                    quality_rating: qualityRating.getValue(),
                    acceptance_opinion:acceptanceOpinion.getValue()
                  },
                  success : function (response, req) {
                    if (Ext.util.JSON.decode(response.responseText).info === "success") {
                      purchaseForApplicantWin.destroy();
                      purchaseDS.reload();
                    } else {
                      Ext.MessageBox.alert('提示', '网络通讯问题.');
                    }
                  },
                  failure : function (result, request){
                  },
                  method : 'POST'
                });
              }
            });
          }
        })

        //入库
        var entryButton = new Ext.Button({
          text: '入库',
          handler: function(){
            Ext.MessageBox.confirm('<font color=red>提示</font>','确定入库吗？',function (button){
              if(button=='yes'){
                Ext.Ajax.request({
                  url : '/purchase/entryPurchase?id='+purchaseId.getValue(),
                  params: {
                    entry_date: entryDate.getValue(),
                    entry_order_number: entryOrderNumber.getValue(),
                    invoice_number: invoiceNumber.getValue(),
                    is_import: isImport.getValue(),
                    produce_date: produceDate.getValue(),
                    purchase_date: purchaseDate.getValue(),
                    product_sn: productSn.getValue(),
                    item_no: itemNo.getValue(),
                    assignment_unit: assignmentUnit.getValue(),
                    instruction: instruction.getValue(),
                    remark: remark.getValue()
                  },
                  success : function (response, req) {
                    if (Ext.util.JSON.decode(response.responseText).info === "success") {
                      purchaseForApplicantWin.destroy();
                      purchaseDS.reload();
                    } else {
                      Ext.MessageBox.alert('提示', '网络通讯问题.');
                    }
                  },
                  failure : function (result, request){
                  },
                  method : 'POST'
                });
              }
            });
          }
        })


        //报账按钮
        var forAccountButton = new Ext.Button({
          text: '报账',
          handler: function(){
            Ext.MessageBox.confirm('<font color=red>提示</font>','您确认要报账吗？',function (button){
              if(button=='yes'){
                Ext.Ajax.request({
                  url : '/purchase/accountPurchase?id='+purchaseId.getValue(),
                  params: {
                    for_account_info: forAccountInfo.getValue()
                  },
                  success : function (response, req) {
                    if (Ext.util.JSON.decode(response.responseText).info === "success") {
                      purchaseForApplicantWin.destroy();
                      purchaseDS.reload();
                    } else {
                      Ext.MessageBox.alert('提示', '网络通讯问题.');
                    }
                  },
                  failure : function (result, request){
                  },
                  method : 'POST'
                });
              }
            });
          }
        })

        
        //如果不是初选 ,则隐藏操作列
        if(searchType.getValue() != 'primary'){
          offerCM.getColumnById(11).hidden = true;
        }else{
          offerCM.getColumnById(10).hidden = true;
        }
        
        //竞价未成时
        acceptancePassButton.setVisible(false);
        acceptanceRejectButton.setVisible(false);
        entryButton.setVisible(false);
        forAccountButton.setVisible(false);
        printEntryButton.setVisible(false);
        
        acceptanceFieldSet.setVisible(false);
        accountFieldSet.setVisible(false);
        entryFieldSet.setVisible(false);
        dateFieldSet.setVisible(true);

        offerGrid.setVisible(false);
        
        if(searchType.getValue() === 'all'){
          offerGrid.setVisible(true);
          acceptanceFieldSet.setVisible(true);
          accountFieldSet.setVisible(true);
          entryFieldSet.setVisible(true);
        }else if(searchType.getValue() === 'primary'){
          offerGrid.setVisible(true);
        }else if(searchType.getValue() === 'auditprimary' || searchType.getValue() === 'reject'){
          offerGrid.setVisible(true);
        } else if(searchType.getValue() === 'pass'){
          acceptancePassButton.setVisible(true);
          acceptanceRejectButton.setVisible(true);
          acceptanceFieldSet.setVisible(true);
          offerGrid.setVisible(true);
        }else if(searchType.getValue() === 'for_entry'){
          entryFieldSet.setVisible(true);
          entryButton.setVisible(true);
          acceptanceFieldSet.setVisible(true);
          offerGrid.setVisible(true);
        }else if(searchType.getValue() === 'for_account'){
          accountFieldSet.setVisible(true);
          forAccountButton.setVisible(true);
          entryFieldSet.setVisible(true);
          printEntryButton.setVisible(true);
          
          acceptanceFieldSet.setVisible(true);
          offerGrid.setVisible(true);
        }else if(searchType.getValue() === 'complete'){
          acceptanceFieldSet.setVisible(true);
          entryFieldSet.setVisible(true);
          accountFieldSet.setVisible(true);
          printEntryButton.setVisible(true);
          offerGrid.setVisible(true);
        }else if(searchType.getValue() === 'audited'){
          dateFieldSet.setVisible(false);
        }
        offerDS.load();


        var purchaseForm = new Ext.FormPanel({
          labelWidth: 75, // label settings here cascade unless overridden
          url:'/purchase/releasePurchase',
          reader: new Ext.data.JsonReader({
            root: 'root'
          }, [{
              name: 'id'
            }, {
              name: 'order_number'
            }, {
              name: 'manager'
            }, {
              name: 'purchase_unit'
            }, {
              name: 'funding_source'
            }, {
              name: 'funding_account'
            }, {
              name: 'funding_nature'
            }, {
              name: 'action_date'
            }, {
              name: 'quantity'
            }, {
              name: 'brand'
            }, {
              name: 'supply_date',
              type: 'date',
              dateFormat: 'Y/m/d'
            }, {
              name: 'supply_address'
            }, {
              name: 'service_lift'
            }, {
              name: 'sub_dept'
            }, {
              name: 'product_name'
            }, {
              name: 'model'
            }, {
              name: 'specification'
            }, {
              name: 'manufacturer'
            }, {
              name: 'unit_price'
            }, {
              name: 'estimated_price'
            }, {
              name: 'estimated_amount'
            }, {
              name: 'qualification'
            }, {
              name: 'service_request'
            }, {
              name: 'reason'
            }, {
              name: 'begin_date',
              type: 'date',
              dateFormat: 'Y/m/d'
            }, {
              name: 'end_date',
              type: 'date',
              dateFormat: 'Y/m/d'
            },{
              name:'service_rating'
            },{
              name:'quality_rating'
            },{
              name: 'acceptance_opinion'
            },{
              name: 'entry_date',
              type: 'date',
              dateFormat: 'Y/m/d'
            },{
              name: 'entry_order_number'
            },{
              name: 'invoice_number'
            },{
              name: 'produce_date',
              type: 'date',
              dateFormat: 'Y/m/d'
            },{
              name: 'purchase_date',
              type: 'date',
              dateFormat: 'Y/m/d'
            },{
              name: 'product_sn'
            },{
              name: 'item_no'
            },{
              name: 'assignment_unit'
            },{
              name: 'instruction'
            },{
              name: 'remark'
            },{
              name: 'for_account_info'
            }]),
          frame:true,
          labelAlign: 'right',
          buttonAlign: 'center',          
          //title: '添加申购单',
          bodyStyle:'padding:5px 5px 0',
          width: 760,
          //height:300,
          items: [{
              layout: 'column',
              border: false,
              items: [{
                  columnWidth: .25,
                  layout: 'form',
                  border: false,
                  items: [orderNumber]
                },{
                  columnWidth: .25,
                  layout: 'form',
                  border: false,
                  items: [purchaseUnit]
                }, {
                  columnWidth: .25,
                  layout: 'form',
                  border: false,
                  items: [subDept]
                }, {
                  columnWidth: .25,
                  layout: 'form',
                  border: false,
                  items: [manager]
                }]
            },{
              layout: 'column',
              border: false,
              items: [{
                  columnWidth: .25,
                  layout: 'form',
                  border: false,
                  items: [fundingSource]
                },{
                  columnWidth: .25,
                  layout: 'form',
                  border: false,
                  items: [fundingAccount]
                },{
                  columnWidth: .25,
                  layout: 'form',
                  border: false,
                  items: [fundingNature]
                },{
                  columnWidth: .25,
                  layout: 'form',
                  border: false,
                  items: [serviceLift]
                }]
            },{
              layout: 'column',
              border: false,
              items: [{
                  columnWidth: .25,
                  layout: 'form',
                  border: false,
                  items: [productName]
                },{
                  columnWidth: .25,
                  layout: 'form',
                  border: false,
                  items: [brand]
                },{
                  columnWidth: .25,
                  layout: 'form',
                  border: false,
                  items: [model]
                },{
                  columnWidth: .25,
                  layout: 'form',
                  border: false,
                  items: [specification]
                }]
            },{
              layout: 'column',
              border: false,
              items: [{
                  columnWidth: .25,
                  layout: 'form',
                  border: false,
                  items: [manufacturer]
                },{
                  columnWidth: .25,
                  layout: 'form',
                  border: false,
                  items: [quantity]
                },{
                  columnWidth: .25,
                  layout: 'form',
                  border: false,
                  items: [estimatedPrice]
                },{
                  columnWidth: .25,
                  layout: 'form',
                  border: false,
                  items: [estimatedAmount]
                }]
            },{
              layout: 'column',
              border: false,
              items: [{
                  columnWidth: 1,
                  layout: 'form',
                  border: false,
                  items: [qualification]
                }]
            },{
              layout: 'column',
              border: false,
              items: [{
                  columnWidth: 1,
                  layout: 'form',
                  border: false,
                  items: [reason]
                }]
            },{
              layout: 'column',
              border: false,
              items: [{
                  columnWidth: .25,
                  layout: 'form',
                  border: false,
                  items: [supplyDate]
                },{
                  columnWidth: .75,
                  layout: 'form',
                  border: false,
                  items: [supplyAddress]
                }]
            },{
              layout: 'column',
              border: false,
              items: [{
                  columnWidth: 1,
                  layout: 'form',
                  border: false,
                  items: [serviceRequest]
                }]
            },dateFieldSet,purchaseId,offerGrid,acceptanceFieldSet,entryFieldSet,accountFieldSet],
          buttons: [printPurchaseButton,printEntryButton,acceptancePassButton,acceptanceRejectButton,entryButton,forAccountButton,{
              text: '取消',
              handler: function(){
                purchaseForApplicantWin.destroy();
              }
            }]
        });

        purchaseForm.form.load({
          url: '/purchase/edit?id=<%=params[:id]%>',
          waitMsg: '正在载入数据...',
          success: function(form, action){
          },
          failure: function(form, action){
            Ext.MessageBox.alert('提示信息', '信息加载失败');
          }
        });        
        
        purchaseForm.render('purchase_form');

      })
    </script>
  </head>
  <body>
    <div id="purchase_form"></div>
  </body>
</html>
